{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2cbee8d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 购物车练习---参考知乎--小二二（好难啊），\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b6e2f6dd",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-17-d485f41da4ff>, line 4)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-17-d485f41da4ff>\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m    [\"手机\"，4000],\u001b[0m\n\u001b[1;37m             ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "#第一步：存放组数\n",
    "shop_car = []\n",
    "goods_list = [\n",
    "    [\"手机\"，4000],\n",
    "    [\"宝马\"，20000]，\n",
    "    [\"毛衣\"，200]，\n",
    "    [\"电脑\"，7000]\n",
    "       \n",
    "]\n",
    "# 商品列表\n",
    "while Ture:\n",
    "    salary = input(\"您有多少钱：\")#输入多少钱\n",
    "    if salary.isdigit():#判断是否为整数\n",
    "        salary = int(salary)# 将字符串转化为整数\n",
    "        print(\"是否要买东西：\")\n",
    "        flagl = input(\"Y  N:\")\n",
    "        if flag.upper() == 'N':# 将字符串大写\n",
    "            exit('欢迎下次光临')#退出程序并输出“欢迎下次光临”\n",
    "        elif flagl.upper() =='Y':\n",
    "            break # 终止循环\n",
    "        elif flagl.upper() =='Q':\n",
    "            exit('欢迎下次光临')\n",
    "        elif salary.upper() == 'Q':\n",
    "            exit(\"欢迎下次光临\")\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d94eb85",
   "metadata": {},
   "outputs": [],
   "source": [
    "##？？？上面啥情况，出问题了，出问题了，找不出，重试一次吧"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "afef392c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "759fb246",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输出您的余额：100\n",
      "-----------【商品列表】----------\n",
      "商品编号：0,商品名称：book,商品的价格：30元\n",
      "商品编号：1,商品名称：pen,商品的价格：10元\n",
      "商品编号：2,商品名称：apple,商品的价格：3元\n",
      "商品编号：3,商品名称：banana,商品的价格：2元\n",
      "请输入正确的商品编号：0\n",
      "【book】 已经添加到您的购物车，您的余额还有 【70】 元\n"
     ]
    }
   ],
   "source": [
    "\n",
    "goods_list = [\n",
    "    [\"book\",30],\n",
    "    [\"pen\",10],\n",
    "    [\"apple\",3],\n",
    "    [\"banana\",2]\n",
    "]\n",
    "users_shopping_car = []\n",
    "Alipay = int(input(\"请输出您的余额：\"))\n",
    "print(\"-----------【商品列表】----------\")\n",
    "for i in range(len(goods_list)):\n",
    "    print(\"商品编号：%s,商品名称：%s,商品的价格：%d元\"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "choice = input(\"请输入正确的商品编号：\")\n",
    "if choice.isdigit():\n",
    "    choice = int(choice)\n",
    "#是正确的编号\n",
    "    if choice < len(goods_list):   #商品的信息：goods_list[choice],商品名称：goods_list[choice][0],商品价格：goods_list[choice][1]\n",
    "    #1.看一看用户钱够不够：Alipay VS goods_list[choice][1]\n",
    "        if Alipay < goods_list[choice][1]:\n",
    "            print(\"您余额不够，请更换支付方式\")\n",
    "        else:\n",
    "            Alipay = Alipay - goods_list[choice][1]\n",
    "            users_shopping_car.append(goods_list[choice])\n",
    "         #提示用户，本次购买成功\n",
    "        print(\"【%s】 已经添加到您的购物车，您的余额还有 【%d】 元\"%(goods_list[choice][0],Alipay))\n",
    "    else:\n",
    "        print(\"您输入的商品不存在，请输入正确的编号\")\n",
    "    pass\n",
    "    \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd1a6dad",
   "metadata": {},
   "outputs": [],
   "source": [
    "#下一阶段\n",
    "# 循环输出\n",
    "#结束"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "92f11881",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "17549860",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef582f97",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
